const nian = ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'];
let nianNumber = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
const yue = ['1号', '2号', '3号', '4号', '5号', '6号', '7号', '8号', '9号', '10号', '11号', '12号', '13号', '14号', '15号', '16号', '17号',
    '18号', '19号', '20号', '21号', '22号', '23号', '24号', '25号', '26号', '27号', '28号', '29号', '30号', '31号'];
let yueNumber1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
let yueNumber2 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
let yueNumber3 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];

function articlesNumber() {
    axios({
        method: "get",
        url: "/content-statistics/articlesNumber",
    }).then(res => {
        $("#total_number_of_articles").html(res.data);
    })
    commentsNumber();
}

function commentsNumber() {
    axios({
        method: "get",
        url: "/content-statistics/commentsNumber",
    }).then(res => {
        $("#number_of_comments").html(res.data);
    })
    readingQuantity();
}

function readingQuantity() {
    axios({
        method: "get",
        url: "/content-statistics/readingQuantity",
    }).then(res => {
        $("#reading_quantity").html(res.data);
    })
    forwardingNumber();
}

function forwardingNumber() {
    axios({
        method: "get",
        url: "/content-statistics/forwardingNumber",
    }).then(res => {
        $("#number_of_forwarding").html(res.data);

    })
    articlesNumberTime('2023-06-01','2023-06-30')
}

function articlesNumberTime(kDate, jDate) {
    axios({
        method: "get",
        url: "/content-statistics/articlesNumberTime/" + kDate + "/" + jDate
    }).then(res => {

        let data = res.data;
        for (let i = 0; i < data.length; i++) {
            for (let j = 0; j < yue.length; j++) {
                console.log(data[i].date+" , "+data[i].number)
                if ((j + 1) == data[i].date) {
                    yueNumber1[j] = data[i].number;
                }
            }
        }
    });
    website_bar_chart(yue, yueNumber1);
}
function readingQuantityTime(kDate, jDate){
    // alert("阅读量-kDate："+kDate+" , jDate:"+jDate)
    axios({
        method: "get",
        url: "/content-statistics/readingQuantityTime/" + kDate + "/" + jDate
    }).then(res => {
        let data = res.data;
        for (let i = 0; i < data.length; i++) {
            for (let j = 0; j < yue.length; j++) {
                console.log(data[i].date+" , "+data[i].number)
                if ((j + 1) == data[i].date) {
                    yueNumber2[j] = data[i].number;
                }
            }
        }
    });
    website_bar_chart(yue, yueNumber2);
}

function commentsNumberTime(kDate, jDate) {
    axios({
        method: "get",
        url: "/content-statistics/commentsNumberTime/" + kDate + "/" + jDate
    }).then(res => {
        let data = res.data;
        for (let i = 0; i < data.length; i++) {
            for (let j = 0; j < yue.length; j++) {
                console.log(data[i].date+" , "+data[i].number)
                if ((j + 1) == data[i].date) {
                    yueNumber3[j] = data[i].number;
                }
            }
        }
    });
    website_bar_chart(yue, yueNumber3);
}
/*柱状图加载...*/
function website_bar_chart(date, number) {
    for (let i =0;i<number.length;i++){
        console.log(number[i]);
    }
    let data = {
        tooltip: {trigger: 'axis'},
        calculable: true,
        xAxis: [{
            type: 'category',
            data: date,
            position: 'left'
        }],
        yAxis: [{
            type: 'value',
            position: 'left'
        }],
        series: [{
            name: 'number',
            type: 'bar',
            data: number,
            color: '#009999' // 设置颜色
        }]
    }
    require.config({paths: {echarts: 'https://echarts.baidu.com/build/dist'}});
    // 使用
    // 使用柱状图就加载bar模块，按需加载
    require(['echarts', 'echarts/chart/bar', 'echarts/chart/line'],
        function (ec) {
            // 为echarts对象加载数据
            ec.init(document.getElementById('main2')).setOption(data);
        }
    );
}